#!/bin/sh

### #####################################################################
## Parse script name
#
SCRIPT=`basename $0`
CMD=`echo ${SCRIPT} | awk -F. ' { print $1 }' | xargs basename`
BLD=`echo ${SCRIPT} | awk -F. ' { print $2 }'`
CFG=`echo ${SCRIPT} | awk -F. ' { print $3 }'`

if [ "${CMD}" != "m" ]; then
    echo "Please ln -s /usr/local/bin/m m.<BLD_TYPE>.<CFG_TYPE>"
    exit
fi

OUTPUT_DIR=${BLD}_${CFG}

### #####################################################################
## Append bkmpost.sh to post_process.sh
#
sed -i "/bkmpost_placeHolder_83264/d" post_process.sh
sed -i "/bkmpost_placeHolder_83264/d" ${OUTPUT_DIR}/ntv_customize_fs.txt

echo '' >> post_process.sh
echo 'echo "${WORKING_DIR}/dazhu/bkmpost.sh ${BUILD_TYPE} ${CONFIG_TYPE} ${WORKING_DIR} bkmpost_placeHolder_83264" >> ${OUTPUT_DIR}/ntv_customize_fs.txt' >> post_process.sh

### #####################################################################
## Run the make command
#
source ../set_env_bash.sh
TM_B=`date +%s`
echo make DEBUG_INIT=1 CONFIG_TYPE=${CFG} BUILD_TYPE=${BLD} $1 $2 $3 $4 $5 $6 $7 $8 $9
make DEBUG_INIT=1 CONFIG_TYPE=${CFG} BUILD_TYPE=${BLD} $1 $2 $3 $4 $5 $6 $7 $8 $9
TM_A=`date +%s`
DIFF=`expr ${TM_A} - ${TM_B}`

echo "Build cost: " `dazhu/fmtTime.py ${DIFF}`

sed -i "/bkmpost_placeHolder_83264/d" post_process.sh
sed -i "/bkmpost_placeHolder_83264/d" ${OUTPUT_DIR}/ntv_customize_fs.txt

